<template>
  <div class="search">
    <f-form ref="form" :action="api.aftersale" :form-key="this.formItem.afterSaleId" :file-ids="fileIds">
      <f-form-item label="保障logo" type="upload" name="afterSaleLogo" :value="formItem.afterSaleLogo" :file-max="1" @uploadSuccess="uploadSuccess"/>
      <f-form-item label="保障名称" name="afterSaleTitle" :required="true" :value="formItem.afterSaleTitle"/>
      <f-form-item label="排序值" type="number"  :required="true" name="sortOrder" :value="formItem.sortOrder"/>
      <f-form-item label="保障简介" name="afterSaleContent" type="editor" :value="formItem.afterSaleContent"/>
    </f-form>
  </div>
</template>

<script>
  export default {
    name: 'AfterSaleForm',
    props: {},
    data() {
      return {
        isAdd: true,//是否是添加模式
        loaded: false,//是否加载轮播图组件
        fileIds: [],//上传文件ID
        formItem: this.getFormItem()
      }
    },
    methods: {
      getFormItem() {
        return {
          afterSaleId: '',
          afterSaleTitle: '',
          sortOrder:99,
          afterSaleLogo: '',
          afterSaleState:0
        }
      },
      //表单赋值
      setData(data) {
        this.$refs.form.resetFields()
        this.formItem = this.getFormItem()
        this.isAdd = true
        if (data && data.afterSaleId) {
          this.$refs.form.getDetails({ afterSaleId: data.afterSaleId }, (data) => {
            this.formItem = data
            this.loaded = true
          })
          this.isAdd = false
        } else {
          this.loaded = true
        }
      },
      //文件上传回调
      uploadSuccess(fileIds, files) {
        this.fileIds = fileIds
      },
      //提交表单
      handleSubmit(callback) {
        this.$refs.form.submit(this.formItem,callback)
      },
    },
    created() {

    },
    components: {}
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

</style>
